import service from "./config";

const http = {
  CONTENT_TYPE: {
    JSON: "application/json",
    FORMDATA: "multipart/form-data",
    URL_ENCODED: "application/x-www-form-urlencoded",
  },

  get(url, params, contentType = this.CONTENT_TYPE.JSON) {
    const config = {
      method: "get",
      url: url,
      contentType: contentType,
    };
    if (params) config.params = params;
    return service(config);
  },
  post(url, params, contentType = this.CONTENT_TYPE.JSON) {
    const config = {
      method: "post",
      url: url,
      contentType: contentType,
    };
    if (params) config.data = params;
    return service(config);
  },
  //应对登录问题
  postUrlEncoded(url, params, contentType = this.CONTENT_TYPE.URL_ENCODED) {
    const config = {
      method: "post",
      url: url,
      contentType: contentType,
    };
    if (params) config.params = params;
    return service(config);
  },
};

export default http;
